<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style type="text/css">
        /* .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .lw {
            background-color: #DCE9F2;
            border-top: 1px solid #CBD6DE;
            border-bottom: 1px solid #ADBECB;
            color: #467aa7;
            font-size: 12px;
            font-weight: bold;
        }

        .lw1 {
            background-color: #f0f5f5;
            border-top: 1px solid #CBD6DE;
            border-bottom: 1px solid #ADBECB;
            color: #467aa7;
            font-size: 12px;
        }

        .table {
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
            font-size: 13px;
            margin-bottom: 15px;
            width: 100%;
            border-collapse: collapse;
        }

        .table td {
            height: 40px;
            text-align: left;
            border: 0px solid #CBD6DE;
            padding: 0;
            margin: 0;
        }

        .aui-searchbar-input {
            width: 95% !important;
        } */
    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            <!-- <span>单号:</span> -->
            <span id="titleVal"></span>
        </div>
    </header>
    <div class="aui-content aui-margin-b-15">
        <div>
            <!-- <div style="width:33%;margin-top:2%;"></div> -->
            <div class="aui-btn aui-btn-info"style="width:30%;margin-left:10%;margin-top:2%;"  onclick="searchKG()"id="kaiguan"></div>
            <!-- <div style="width:100%;margin-top:2%;"></div> -->
            <div class="aui-btn aui-btn-info" style="width:30%;margin-left:20%;margin-top:2%;"onclick="doSerach()">查询</div> 
        </div>
        <div style="width:100%;margin-top:2%;"></div>

        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;">
            <table class="table" style='width:120%' id="table">
                <thead>
                    <tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 12px;font-weight: bold;">
                        <!-- <td algin='center'></td> -->
                        <td algin='center'>vin</td>
                        <td algin='center'>发货顺序号</td>
                        <td algin='center'>气门嘴码</td>
                        <td algin='center'>气门嘴顺序号</td>
                        <td algin='center'>车型号</td>
                        <td algin='center'>发货状态</td>
                        <td style="display:none;">id</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>

    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    //光标所在id
    var idSelector = "";
    var fhcode = ""; //仓库GID
    var interval;
    var lotCode = "";
    var qty = "";
    var boxnum = "";
    var tmId = "";

    apiready = function() {

        $api.html($api.byId("titleVal"), api.pageParam.code);
        //$api.html($api.byId("titleVal"), api.pageParam.invoicedate)
        idSelector = "workCenterCode";
        $("#workCenterCode").focus();
        fhcode = api.pageParam.code;
        searchKG();
        //获取发货单已经绑定的明细
        //searchDetails(api.pageParam.code);

    }

    function searchKG() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/deliveryWheelOnlineRisk";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                appVersion: api.appVersion,
                Switch: "ON"
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var kg = myobj.kg;
                    var div = document.getElementById("kaiguan")
                    if(kg == "0"){//关闭
                        div.innerText="开关:关";
                        clearInterval(interval)
                    }else if(kg == "1"){
                        div.innerText="开关:开";
                        interval = setInterval("doSerach()","1000");
                    }

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });

    }
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }
    function doSerach(){
        searchDetails(fhcode);
    };
   //根据发货单查询表格数据
   function searchDetails(code) {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/deliveryWheelOnlineRisk";
        var data = {
            values: { ////以表单方式提交参数（JSON对象）
                un: un,
                appVersion: api.appVersion,
                code: code
            }
        };

        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {

                    var list = myobj.list;
                    var html = "";

                    var color = ['#F5F5F5', '#DCDCDC'];
                    var index = 0;
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        // if (i == 0) {
                        //     html += "<tr style='text-align: center;background-color: " + color[index] + ";color: black;font-size: 12px;'>";
                        // } else {
                        //     if (list[i].vin != list[i - 1].vin) {
                        //         if (index == 0) {
                        //             index = 1;
                        //         } else {
                        //             index = 0;
                        //         }
                        //     }
                        //     html += "<tr style='text-align: center;background-color: " + color[index] + ";color: black;font-size: 12px;'>";
                        // }
                        html += "<tr style='text-align: center;background-color: #F5F5F5;color: black;font-size: 12px;'>";
                        // html += "<td ><input name='sub' type='checkbox' /></td>";
                        html += "<td name='vin' algin='center'>" + list[i].vin + "</td>";
                        html += "<td name='ext06' algin='center'>" + list[i].ext06 + "</td>";
                        if (list[i].ext08 == null || list[i].ext08 == undefined) {
                            html += "<td name='ext08' algin='center'></td>";
                        } else {
                            html += "<td name='ext08' algin='center'>" + list[i].ext08 + "</td>";
                        }
                        if (list[i].ext05 == null || list[i].ext05 == undefined) {
                            html += "<td name='ext05' algin='center'></td>";
                        } else {
                            html += "<td name='ext05' algin='center'>" + list[i].ext05 + "</td>";
                        }
                        html += "<td name='sub_mrlcode' algin='center'>" + list[i].sub_mrlcode + "</td>";
                        if (list[i].ext11 == 'Y') {
                            html += "<td name='ext11' style='background-color:#228B22;'algin='center'>" + list[i].ext11 + "</td>";
                        } else {
                            html += "<td name='ext11'algin='center'>" + list[i].ext11 + "</td>";
                        }
                        html += "<td name='sysid' style='display:none;'>" + list[i].sysid + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    $("#consignment").select();
                    idSelector = "consignment";
                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});

        api.execScript({
            name: "wmRiskLibraryShipment",
            script: 'refreshData()'
        });
    }
</script>

</html>
